package com.btl.service.ai.biz.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.btl.service.ai.auth.SecurityContextHolder;
import com.btl.service.ai.biz.entity.KwSegment;
import com.btl.service.ai.biz.mapper.KwSegmentMapper;
import com.btl.service.ai.biz.service.IKwSegmentService;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author Tim
 * @since 2025-08-11
 */
@Service
public class KwSegmentServiceImpl extends ServiceImpl<KwSegmentMapper, KwSegment> implements IKwSegmentService {

    /**
     * 分段分页
     *
     * @param current    当前页码
     * @param size       每页数量
     * @param documentId 文档ID
     * @return Page<KwDocument>
     */
    @Override
    public Page<KwSegment> page(Long documentId, Integer current, Integer size) {
        Long childId = SecurityContextHolder.get()
                .getChildId();
        return this.page(Page.of(current, size), new LambdaQueryWrapper<KwSegment>()
                .eq(KwSegment::getChildId, childId)
                .eq(KwSegment::getDocumentId, documentId)
                .orderByDesc(KwSegment::getId));
    }
}
